import os
from django.conf import settings

class BaiduConfig:
    """百度智能云配置管理类"""
    
    # 默认API配置（如人脸识别、通用OCR等）
    API_KEY = getattr(settings, 'BAIDU_API_KEY', "To3mbciFTCbp0uM7FGWuWjqd")
    SECRET_KEY = getattr(settings, 'BAIDU_SECRET_KEY', "EWO2Ir8VTX8AbCX0N1XpnLzoLMFMC9qF")

    # 身份证OCR专用
    IDCARD_API_KEY = "QhkuDXNlBsSqzfeXBkmJyYZX"
    IDCARD_SECRET_KEY = "yMwBzt2oWWOa1AuPeVeee3SJpkeriJNG"
    
    # Token缓存配置
    TOKEN_CACHE_KEY = "baidu_ai_access_token"
    TOKEN_CACHE_EXPIRE = 2592000  # 30天，百度token有效期30天
    
    # API端点配置
    BASE_URL = "https://aip.baidubce.com/rest/2.0"
    TOKEN_URL = "https://aip.baidubce.com/oauth/2.0/token"
    
    # OCR API配置
    OCR_ENDPOINTS = {
        'idcard': 'ocr/v1/idcard',
        'accurate_basic': 'ocr/v1/accurate_basic',
        'general_basic': 'ocr/v1/general_basic',
    }
    
    # 请求超时配置
    REQUEST_TIMEOUT = 30
    
    @classmethod
    def get_api_key(cls, service='default'):
        if service == 'idcard':
            return cls.IDCARD_API_KEY
        return cls.API_KEY
    
    @classmethod
    def get_secret_key(cls, service='default'):
        if service == 'idcard':
            return cls.IDCARD_SECRET_KEY
        return cls.SECRET_KEY
    
    @classmethod
    def get_token_url(cls):
        """获取Token获取URL"""
        return cls.TOKEN_URL
    
    @classmethod
    def get_base_url(cls):
        """获取基础URL"""
        return cls.BASE_URL
    
    @classmethod
    def get_ocr_endpoint(cls, endpoint_name):
        """获取OCR端点URL"""
        return cls.OCR_ENDPOINTS.get(endpoint_name)
    
    @classmethod
    def get_request_timeout(cls):
        """获取请求超时时间"""
        return cls.REQUEST_TIMEOUT
    
    @classmethod
    def get_token_cache_config(cls):
        """获取Token缓存配置"""
        return {
            'key': cls.TOKEN_CACHE_KEY,
            'expire': cls.TOKEN_CACHE_EXPIRE
        } 